<template>
  <div>
    <a-row>
      <a-row>
        <a-card size="small">
          <a-space>
            <a-button type="primary" v-has="'btn_SEM3400_query'"  @click="queryTreeData" v-shortcut="'F1'">
              {{$t('btn.query')}}
            </a-button>

            <a-button type="primary" v-has="'btn_SEM3400_add'" @click="add" v-shortcut="'F2'">
              {{$t('btn.add')}}
            </a-button>

            <a-button  type="primary" v-has="'btn_SEM3400_update'" @click="edit" v-shortcut="'F3'">
              {{$t('btn.update')}}
            </a-button>

            <a-button type="danger" v-has="'btn_SEM3400_delete'" @click="remove" v-shortcut="'F4'">
              {{$t('btn.delete')}}
            </a-button>
            <a-button type="primary" v-has="'btn_SEM3400_add_type'" @click="AddDataCate" v-shortcut="'F6'">
              {{$t('btn.addType')}}
            </a-button>
            <a-button type="primary" v-has="'btn_SEM3400_update_type'" @click="updateDataCate" v-shortcut="'F7'">
              {{$t('btn.updateType')}}
            </a-button>
            <a-button type="danger" v-has="'btn_SEM3400_delete_type'" @click="deleteDataCate" v-shortcut="'F8'">
              {{$t('btn.deleteType')}}
            </a-button>
          </a-space>
        </a-card>
      </a-row>
    </a-row>

    <a-modal :title="$t(title)" v-model="cateVisible" @ok="handleOk" :okText="$t('menuItem.confirm')"
             :cancelText="$t('menuItem.cancel')"
             @cancel="closeModal"
             :width="modalWidth">
      <a-form-model :model="cateForm" ref="cateAddForm" layout="inline" :rules="cateRule" :label-col="{span: 12}"
                    :wrapper-col="{span: 9}">
        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('parameterType')" prop="m_para_type">
              <a-input v-model="cateForm.m_para_type"
                       @change="cateForm.m_para_type = cateForm.m_para_type.toUpperCase()"
                       allowClear
                       :disabled="updateType"
              ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('parameterTypeDescription')" prop="m_para_desc">
              <a-input v-model="cateForm.m_para_desc"
                       @change="cateForm.m_para_desc = cateForm.m_para_desc.toUpperCase()"
                       allowClear></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('parameterDescription')" prop="m_data_desc">
              <a-input v-model="cateForm.m_data_desc.value"
                       @change="cateInputChange('m_data_desc')"
                       allowClear>
                                <span
                                    slot="addonAfter"
                                    v-if="cateForm.m_data_desc.defaultValue"
                                    @click="cateAddColumns('m_data_desc', cateForm.m_data_desc)"
                                >
                                    默认值：{{cateForm.m_data_desc.defaultValue}}
                                </span>
              </a-input>
            </a-form-model-item>
          </a-col>
          <value-setting @showDefaultModal="cateAddColumns('m_data_desc', cateForm.m_data_desc)"
                         ref="DATA_DESC" v-if="cateForm.m_data_desc.value" :settingForm="cateForm.m_data_desc"
                         :valueName="'dataDesc'"></value-setting>
        </a-row>
        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('firstColumnMeaning')">
              <a-input v-model="cateForm.m_data_id.value"
                       @change="cateInputChange('m_data_id') "
                       allowClear
              >
                                <span
                                    slot="addonAfter"
                                    v-if="cateForm.m_data_id.defaultValue"
                                    @click="cateAddColumns('m_data_id', cateForm.m_data_id)">
                                    默认值：{{cateForm.m_data_id.defaultValue}}
                                </span>
              </a-input>
            </a-form-model-item>
          </a-col>
          <value-setting @showDefaultModal="cateAddColumns('m_data_id', cateForm.m_data_id)" ref="DATA_ID"
                         v-if="cateForm.m_data_id.value" :settingForm="cateForm.m_data_id"
                         :valueName="'dataId'"></value-setting>
        </a-row>
        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('secondColumnMeaning')">
              <a-input v-model="cateForm.m_data_ext.value"
                       @change="cateInputChange('m_data_ext')"
                       allowClear>
                                <span
                                    slot="addonAfter"
                                    v-if="cateForm.m_data_ext.defaultValue"
                                    @click="cateAddColumns('m_data_ext', cateForm.m_data_ext)"
                                >
                                    默认值：{{cateForm.m_data_ext.defaultValue}}
                                </span>
              </a-input>
            </a-form-model-item>
          </a-col>
          <value-setting @showDefaultModal="cateAddColumns('m_data_ext', cateForm.m_data_ext)" ref="DATA_EXT"
                         v-if="cateForm.m_data_ext.value" :settingForm="cateForm.m_data_ext"
                         :valueName="'dataExt'"></value-setting>
        </a-row>
        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('thirdColumnMeaning')">
              <a-input v-model="cateForm.m_data_item.value"
                       @change="cateInputChange('m_data_item')"
                       allowClear>
                                <span
                                    slot="addonAfter"
                                    v-if="cateForm.m_data_item.defaultValue"
                                    @click="cateAddColumns('m_data_item', cateForm.m_data_item)"
                                >
                                    默认值：{{cateForm.m_data_item.defaultValue}}
                                </span>
              </a-input>
            </a-form-model-item>
          </a-col>
          <value-setting @showDefaultModal="cateAddColumns('m_data_item', cateForm.m_data_item)"
                         ref="DATA_ITEM" v-if="cateForm.m_data_item.value" :settingForm="cateForm.m_data_item"
                         :valueName="'dataItem'"></value-setting>
        </a-row>

        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('fourthColumnMeaning')">
              <a-input v-model="cateForm.m_ext_1.value"
                       @change="cateInputChange('m_ext_1')"
                       allowClear>
                                <span
                                    slot="addonAfter"
                                    v-if="cateForm.m_ext_1.defaultValue"
                                    @click="cateAddColumns('m_ext_1', cateForm.m_ext_1)"
                                >
                                    默认值：{{cateForm.m_ext_1.defaultValue}}
                                </span>
              </a-input>
            </a-form-model-item>
          </a-col>
          <value-setting @showDefaultModal="cateAddColumns('m_ext_1', cateForm.m_ext_1)" ref="EXT_1"
                         v-if="cateForm.m_ext_1.value" :settingForm="cateForm.m_ext_1"
                         :valueName="'dataExt1'"></value-setting>
        </a-row>
        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('fifthColumnMeaning')">
              <a-input v-model="cateForm.m_ext_2.value"
                       @change="cateInputChange('m_ext_2')"
                       allowClear>
                                <span
                                    slot="addonAfter"
                                    v-if="cateForm.m_ext_2.defaultValue"
                                    @click="cateAddColumns('m_ext_2', cateForm.m_ext_2)"
                                >
                                    默认值：{{cateForm.m_ext_2.defaultValue}}
                                </span>
              </a-input>
            </a-form-model-item>
          </a-col>
          <value-setting @showDefaultModal="cateAddColumns('m_ext_2', cateForm.m_ext_2)" ref="EXT_2"
                         v-if="cateForm.m_ext_2.value" :settingForm="cateForm.m_ext_2"
                         :valueName="'dataExt2'"></value-setting>
        </a-row>
        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('sixthColumnMeaning')">
              <a-input v-model="cateForm.m_ext_3.value"
                       @change="cateInputChange('m_ext_3')"
                       allowClear>
                                <span
                                    slot="addonAfter"
                                    v-if="cateForm.m_ext_3.defaultValue"
                                    @click="cateAddColumns('m_ext_3', cateForm.m_ext_3)"
                                >
                                    默认值：{{cateForm.m_ext_3.defaultValue}}
                                </span>
              </a-input>
            </a-form-model-item>
          </a-col>
          <value-setting @showDefaultModal="cateAddColumns('m_ext_3', cateForm.m_ext_3)" ref="EXT_3"
                         v-if="cateForm.m_ext_3.value" :settingForm="cateForm.m_ext_3"
                         :valueName="'dataExt3'"></value-setting>
        </a-row>
        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('seventhColumnMeaning')">
              <a-input v-model="cateForm.m_ext_4.value"
                       @change="cateInputChange('m_ext_4')"
                       allowClear>
                                <span
                                    slot="addonAfter"
                                    v-if="cateForm.m_ext_4.defaultValue"
                                    @click="cateAddColumns('m_ext_4', cateForm.m_ext_4)"
                                >
                                    默认值：{{cateForm.m_ext_4.defaultValue}}
                                </span>
              </a-input>
            </a-form-model-item>
          </a-col>
          <value-setting @showDefaultModal="cateAddColumns('m_ext_4', cateForm.m_ext_4)" ref="EXT_4"
                         v-if="cateForm.m_ext_4.value" :settingForm="cateForm.m_ext_4"
                         :valueName="'dataExt4'"></value-setting>
        </a-row>
        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('eighthColumnMeaning')">
              <a-input v-model="cateForm.m_ext_5.value"
                       @change="cateInputChange('m_ext_5')"
                       allowClear>
                                <span
                                    slot="addonAfter"
                                    v-if="cateForm.m_ext_5.defaultValue"
                                    @click="cateAddColumns('m_ext_5', cateForm.m_ext_5)"
                                >
                                    默认值：{{cateForm.m_ext_5.defaultValue}}
                                </span>
              </a-input>
            </a-form-model-item>
          </a-col>
          <value-setting @showDefaultModal="cateAddColumns('m_ext_5', cateForm.m_ext_5)" ref="EXT_5"
                         v-if="cateForm.m_ext_5.value" :settingForm="cateForm.m_ext_5"
                         :valueName="'dataExt5'"></value-setting>
        </a-row>
        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('ninthColumnMeaning')">
              <a-input v-model="cateForm.m_ext_6.value"
                       @change="cateInputChange('m_ext_6')"
                       allowClear>
                                <span
                                    slot="addonAfter"
                                    v-if="cateForm.m_ext_6.defaultValue"
                                    @click="cateAddColumns('m_ext_6', cateForm.m_ext_6)"
                                >
                                    默认值：{{cateForm.m_ext_6.defaultValue}}
                                </span>
              </a-input>
            </a-form-model-item>
          </a-col>
          <value-setting @showDefaultModal="cateAddColumns('m_ext_6', cateForm.m_ext_6)" ref="EXT_6"
                         v-if="cateForm.m_ext_6.value" :settingForm="cateForm.m_ext_6"
                         :valueName="'dataExt6'"></value-setting>
        </a-row>

        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('tenthColumnMeaning')">
              <a-input v-model="cateForm.m_ext_7.value"
                       @change="cateInputChange('m_ext_7')"
                       allowClear>
                                <span
                                    slot="addonAfter"
                                    v-if="cateForm.m_ext_7.defaultValue"
                                    @click="cateAddColumns('m_ext_7', cateForm.m_ext_7)"
                                >
                                    默认值：{{cateForm.m_ext_7.defaultValue}}
                                </span>
              </a-input>
            </a-form-model-item>
          </a-col>
          <value-setting @showDefaultModal="cateAddColumns('m_ext_7', cateForm.m_ext_7)" ref="EXT_7"
                         v-if="cateForm.m_ext_7.value" :settingForm="cateForm.m_ext_7"
                         :valueName="'dataExt7'"></value-setting>
        </a-row>
        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('eleventhColumnMeaning')">
              <a-input v-model="cateForm.m_ext_8.value"
                       @change="cateInputChange('m_ext_8')"
                       allowClear>
                                <span
                                    slot="addonAfter"
                                    v-if="cateForm.m_ext_8.defaultValue"
                                    @click="cateAddColumns('m_ext_8', cateForm.m_ext_8)"
                                >
                                    默认值：{{cateForm.m_ext_8.defaultValue}}
                                </span>
              </a-input>
            </a-form-model-item>
          </a-col>
          <value-setting @showDefaultModal="cateAddColumns('m_ext_8', cateForm.m_ext_8)" ref="EXT_8"
                         v-if="cateForm.m_ext_8.value" :settingForm="cateForm.m_ext_8"
                         :valueName="'dataExt8'"></value-setting>
        </a-row>
        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('twelfthColumnMeaning')">
              <a-input v-model="cateForm.m_ext_9.value"
                       @change="cateInputChange('m_ext_9')"
                       allowClear>
                                <span
                                    slot="addonAfter"
                                    v-if="cateForm.m_ext_9.defaultValue"
                                    @click="cateAddColumns('m_ext_9', cateForm.m_ext_9)"
                                >
                                    默认值：{{cateForm.m_ext_9.defaultValue}}
                                </span>
              </a-input>
            </a-form-model-item>
          </a-col>
          <value-setting @showDefaultModal="cateAddColumns('m_ext_9', cateForm.m_ext_9)" ref="EXT_9"
                         v-if="cateForm.m_ext_9.value" :settingForm="cateForm.m_ext_9"
                         :valueName="'dataExt9'"></value-setting>
        </a-row>
        <a-row>
          <a-col :span="settingCol">
            <a-form-model-item :label="$t('thirteenthColumnMeaning')">
              <a-input v-model="cateForm.m_ext_10.value"
                       @change="cateInputChange('m_ext_10')"
                       allowClear>
                                <span
                                    slot="addonAfter"
                                    v-if="cateForm.m_ext_10.defaultValue"
                                    @click="cateAddColumns('m_ext_10', cateForm.m_ext_10)"
                                >
                                    默认值：{{cateForm.m_ext_10.defaultValue}}
                                </span>
              </a-input>
            </a-form-model-item>
          </a-col>
          <value-setting @showDefaultModal="cateAddColumns('m_ext_10', cateForm.m_ext_10)" ref="EXT_10"
                         v-if="cateForm.m_ext_10.value" :settingForm="cateForm.m_ext_10"
                         :valueName="'dataExt10'"></value-setting>
        </a-row>

<!--        <a-row>-->
<!--          <a-col :span="settingCol">-->
<!--            <a-form-model-item :label="$t('authFlg')">-->
<!--              <a-select v-model="cateForm.authFlg" allowClear showSearch optionFilterProp="children">-->
<!--                <a-select-option v-for="item in authData" :key="item.value" :value="item.value" :title="item.label">-->
<!--                  {{item.label}}-->
<!--                </a-select-option>-->
<!--              </a-select>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--        </a-row>-->
      </a-form-model>
    </a-modal>

    <a-modal :title="$t('deleteParameterType')" v-model="deleteVisible" @ok="handleDeleteOk" :okText="$t('menuItem.confirm')"
             :cancelText="$t('menuItem.cancel')">
      <a-form-model>
        <a-form-model-item :label="$t('parameterType')" :label-col="{span: 8}" :wrapper-col="{span: 16}">
          <a-row>
            <a-col :xs="14" :sm="14">
              <a-select showSearch optionFilterProp="children"  v-model="deleteValue">
                <a-select-option v-for="row in paramData" :value="row.dataId"
                                 :key="row.dataSeqId" :title="row.dataId +':' +row.dataDesc">
                  {{row.dataId +':' +row.dataDesc}}
                </a-select-option>
              </a-select>
            </a-col>
            <a-col :xs="10" :sm=10>
              <span style="color: silver;margin-left: 6px">{{selectDataCateDesc}}</span>
            </a-col>
          </a-row>
        </a-form-model-item>
      </a-form-model>
    </a-modal>


    <a-row class="fullsemi-page-content">
      <a-col :span="6">
        <a-card class="fullsemi-page-content-card-fix">
          <a-input-search @change="localSearch" v-model="treeSearchKey"   allowClear></a-input-search>

          <m-tree
              :loading="loadTree"
              :tree-data="treeData"
              :selectedTreeNodeKey="selectedTreeNodeKey"
              :defaultExpandedKeys="expandedKeys"
              :expandedKeys="loadedKeys"
              :treeClick="onSelect"
              :loadedKeys="loadedKeys"
              :loadDataAsync="true"
              :loadData="onLoadData"
              :expand="onExpand"
          ></m-tree>

        </a-card>
      </a-col>


      <a-col :span="18">
        <a-card class="fullsemi-page-content-card-fix">
          <a-card>
            <template slot="title">
              <a-icon type="bulb"/>
              {{$t('parameterItemDetails')}}
            </template>
            <a-form-model :model="paramForm" layout="inline" :rules="paramFormRules" ref="paramForm">
              <a-form-model-item v-for="item in formDataList" :label="item.text"
                                 :label-col="{span: 6}" :wrapper-col="{span: 18}"
                                 :key="item.dataSeqId" :prop="item.key" :ref="item.key" :autoLink="false">
                <a-row>
                  <a-col v-if="item.itemSelectFlag" :xs="16" :sm="16">
                    <a-select showSearch optionFilterProp="children"  v-model="paramForm[item.key]" :disabled="item.disableFlag"
                              @change="handleItemChange"
                              @blur="() => {$refs[item.key][0].onFieldBlur()}">
                      <a-select-option v-for="row in paramData" :value="row.dataId"
                                       :key="row.dataSeqId"
                                       :title="row.dataId +':' +row.dataDesc">
                        {{row.dataId+':'+row.dataDesc}}
                      </a-select-option>
                    </a-select>
                  </a-col>
                  <a-col v-else-if="item.ext2 ===VALUE_TYPE_INT || item.ext2 === VALUE_TYPE_DOUBLE"
                         :xs="16" :sm="16">
                    <a-input-number v-model="paramForm[item.key]" :disabled="item.disableFlag"
                                    :required="item.requireFlag"
                                    :precision="item.ext2 === VALUE_TYPE_DOUBLE ? Number(item.ext5) : 0"
                                    :max="Number(item.ext3)" :min="Number(item.ext4)"
                                    @blur="() => {$refs[item.key][0].onFieldBlur()}"
                                    style="width: 100%"/>
                  </a-col>
                  <a-col v-else :xs="16" :sm="16">
                    <a-input v-model="paramForm[item.key]" :disabled="item.disableFlag"
                             :required="item.requireFlag"
                             @change="paramForm[item.key] = paramForm[item.key]"
                             @blur="() => {$refs[item.key][0].onFieldBlur()}"/>
                  </a-col>
                  <a-col :xs="8" :sm="8">
                                            <span v-if="item.descFlag"
                                                  style="color: silver;margin-left: 6px">{{selectDataCateDesc}}</span>
                  </a-col>
                </a-row>
              </a-form-model-item>
            </a-form-model>
            <a-row type="flex" justify="center">
              <a-button type="primary" @click="handleSubmit" v-if="saveButtonShow" :loading="saveLoading">
                {{$t('btn.save')}}
              </a-button>
            </a-row>
          </a-card>
        </a-card>
      </a-col>
    </a-row>

    <a-modal
        title="设置默认值"
        v-model="defaultValueModalVisible"
        :maskClosable="false"
        :closable="false"
        :keyboard="false"
    >
      <a-form-model :model="defaultValueForm" ref="defaultValueForm" layout="vertical" :rules="defaultValueRules"
      >
        <a-form-model-item :label="`Please Input[${currentColumn.dataExt}]默认值`" prop="value" ref="defaultValue" >
          <a-input-number
              v-if="currentColumn.data.valueType ===VALUE_TYPE_INT || currentColumn.data.valueType === VALUE_TYPE_DOUBLE"
              v-model="defaultValueForm.value"
              :precision="currentColumn.data.valueType === VALUE_TYPE_DOUBLE ? Number(currentColumn.data.valueAccuracy) : 0"
              :max="Number(currentColumn.data.valueMax)" :min="Number(currentColumn.data.valueMin)"
              @blur="() => {$refs.defaultValue.onFieldBlur()}" style="width: 100%"/>
          <a-input
              v-else
              v-model="defaultValueForm.value"
              @change="defaultValueForm.value = defaultValueForm.value.toUpperCase()"
              @blur="() => {$refs.defaultValue.onFieldBlur()}"/>
        </a-form-model-item>
      </a-form-model>
      <template slot="footer">
        <a-button type="primary" @click="closeDefaultValueModal">{{$t('menuItem.confirm')}}</a-button>
      </template>
    </a-modal>


  </div>
</template>
<script>
import {mapGetters, mapMutations, mapState} from "vuex";
import {mixinDevice} from '@/util/mixin';
import MTree from "../../../components/MTree";
import SendMsg from "../../../api/SendMsg";
import ValueSetting from "./ValueSetting";
import {validateLength} from "../../../util/ValidateCateLength.js";
import lodash from 'lodash'

const VALUE_TYPE_STR = 'STR'
const VALUE_TYPE_INT = 'INT'
const VALUE_TYPE_DOUBLE = 'DOUBLE'

export default {
  mixins: [mixinDevice],
  components: {ValueSetting, MTree},
  data() {
    return {
      VALUE_TYPE_STR,
      VALUE_TYPE_INT,
      VALUE_TYPE_DOUBLE,
      authData: [
        {
          label: 'S',
          value: 'S',
        },
        {
          label: 'A',
          value: 'A',
        }
      ],
      title: '',
      modalWidth: '30%',
      settingCol: 24,
      expandedKeys: ['0-0'],//树形控件展开的key集合
      cateVisible: false,//添加类型弹出框是否显示
      deleteVisible: false,//删除类型弹出框是否显示
      saveButtonShow: false,//提交按钮是否显示
      selectedKey: "",//树形控件选中节点的key
      submitType: "",//提交按钮类型（新增/修改）
      deleteValue: "",//删除类型弹出框选中需要删除的参数类型
      selectDataKeys: [],//selectData默认text值
      deleteDesc: "",
      selectedOption: "",//树形控件选中节点值作为下拉菜单默认值
      paramForm: {
        dataCate: ''
      },
      cateRule: {
        m_para_type: [{required: true, message: this.$i18n.tc('menuItem.PleasePermissionType'), trigger: 'blur'},
          {len: 4, message: this.$i18n.tc('menuItem.PleasePermissionTypeWarn')}],
        m_para_desc: [{required: true, message: this.$i18n.tc('menuItem.PleasePermissionTypeDesc'), trigger: 'blur'},],
        m_data_desc: {
          type: 'object',
          required: true,
          fields: {
            value: {required: true, message: this.$i18n.tc('menuItem.PleasePermissionDesc'), trigger: 'blur'},
          }
        },
      },

      saveLoading: false,
      confirmLoading: false,
      selectedTreeNodeKey: '',
      treeSearchKey: '',
      treeSelectedNode: {},
      updateType: false,
      defaultValueModalVisible: false,
      currentColumn: {
        data: {},
        dataExt: ''
      },
      defaultValueForm: {
        value: ''
      },
      defaultValueRules: {}
    };
  },
  computed: {
    ...mapState('js3400', ['cateDataCnt','treeLoadedKeys','cateOldColumns','VALUE_NAME','cateForm','cateData', 'treeData', 'selectData', 'codeData', 'loadTree','paramFormRules','mainFlgArray']),
    ...mapGetters('js3400', ['formDataList', 'paramData']),

    selectDataCateDesc: {
      get: function () {
        return this.$store.state.js3400.selectDataCateDesc
      },
      set: function (val) {
        this.updateSelectDataCateDesc(val)
      }
    },
    loadedKeys: {
      get () {
        return this.treeLoadedKeys
      },
      set(val){
        this.setTreeLoadedKeys(val)
      }
    }
  },
  methods: {
    ...mapMutations('js3400', ['queryCateDataCnt','setCateForm','queryAllCateInfo', 'requestCode', 'initAddParamForm', 'showCodeDetail', 'requestChildrenNode',
      'dataItemQuery', 'addCateData', 'removeCateData', 'addTreeData', 'updateTreeData', 'removeTreeData',
      'udpateFormData', 'cleanFormData', 'updateSelectDataCateDesc', 'searchParamInfo', 'updateTypeFunc','setTreeLoadedKeys']),
    cateInputChange(column) {
      this.cateForm[column].value = this.cateForm[column].value.toUpperCase()
      if (!this.cateForm[column].value) {
        this.cateForm[column] = {
          value: '',
          mainFlg: false,
          valueType: VALUE_TYPE_STR, valueMax: null, valueMin: null,
          valueLength: null,
          valueAccuracy: null,
        }
      }
    },
    closeDefaultValueModal() {
      this.$refs.defaultValueForm.validate(valid => {
        if (valid) {
          this.defaultValueModalVisible = false
          this.cateForm[this.currentColumn.column].defaultValue = this.defaultValueForm.value
          this.$refs.defaultValueForm.resetFields()
        }
      })
    },
    cateAddColumns(column, obj) {
      // 当前类型未添加参数时，不需要输入默认值
      if(!this.cateDataCnt){
        return
      }
      if (!this.updateType) {
        return
      }
      if (obj.value) {
        this.currentColumn = {
          data: {},
          dataExt: ''
        }
        this.defaultValueForm.value = obj.defaultValue || ''
        let key = this.VALUE_NAME[column]
        let index = this.cateOldColumns.findIndex(e => e === key)
        if (index === -1) {
          this.defaultValueModalVisible = true
          this.currentColumn = {
            column: column,
            data: obj,
            dataExt: this.VALUE_NAME[column],
          }

          let item = obj
          let number = this.VALUE_NAME[column].indexOf("_");
          let s = this.VALUE_NAME[column].replace("_", "").toLowerCase();
          let key = s.substring(0, number) + s.charAt(number).toUpperCase() + s.substring(number + 1)
          switch (this.cateForm[column].valueType) {
            case VALUE_TYPE_STR:
              this.defaultValueRules = {
                value: [
                  {required: obj.mainFlg, message: `请输入默认值`, trigger: 'blur'},
                  {validator: (rule, value, callback) => validateLength(value, callback, key, item.valueLength), trigger: 'blur'},
                ]
              }
              break;
            case VALUE_TYPE_INT:
              this.defaultValueRules = {
                value: [
                  {required: obj.mainFlg, message: `请输入默认值，值为整数`, trigger: 'blur'},
                  {validator: (rule, value, callback) => validateLength(value, callback, key, Infinity), trigger: 'blur'},
                ]
              }
              break;
            case VALUE_TYPE_DOUBLE:
              this.defaultValueRules = {
                value: [
                  {required: obj.mainFlg, message: `请输入默认值，小数点后保留${item.valueAccuracy}位`, trigger: 'blur'},
                  {validator: (rule, value, callback) => validateLength(value, callback, key, Infinity), trigger: 'blur'},
                ]
              }
              break;
            default:
          }

        }
      }
    },
    localSearch() {
      this.treeSearchKey = this.treeSearchKey.toUpperCase()
      this.searchParamInfo(this.treeSearchKey)
    },
    //树状控件数据查询
    queryTreeData() {
      this.cleanFormData();
      this.queryAllCateInfo(this.treeSearchKey);
    },
    toUpperCase(e) {
      this.cateForm.m_para_type = e.target.value.toUpperCase()
    },
    //获取树形控件节点
    onExpand(expandedKeys, {expanded, node}) {
      this.expandedKeys = expandedKeys
      this.loadedKeys = expandedKeys
      if (node.dataRef.key == '0-0') {
        return
      }
      if (expanded) {
        // this.requestChildrenNode({data: node.dataRef})
      }
    },
    onLoadData(node) {
      if (node.dataRef.key == '0-0') {
        return new Promise(resolve => {
          resolve()
        });
      }
      return new Promise(resolve => {
        this.requestChildrenNode({data: node.dataRef, resolve: resolve})
      });
    },
    //参数Tree选中事件
    onSelect(selectedKeys, {selected, node}) {
      this.$refs.paramForm.resetFields()
      this.selectedTreeNodeKey = ''
      if (!selected) {
        this.saveButtonShow = false;
        this.selectedTreeNodeKey = ''
        this.treeSelectedNode = {}
        this.selectedOption = ''
        this.cleanFormData();
        return;
      }
      this.saveButtonShow = false;
      if (node.dataRef.key == '0-0') {
        this.cleanFormData();
        return;
      }
      if (node.dataRef.nodeType == 'cate') {
        this.selectedOption = "cate";
        this.showCodeDetail(node.dataRef.obj)
        this.selectedTreeNodeKey = selectedKeys[0]
        this.treeSelectedNode = node.dataRef.obj
      } else {
        // 选中叶子节点，显示叶子详细信息
        this.selectedKey = node.dataRef.key;
        this.onSelectQuery(this.selectedKey, node);
        this.selectedOption = "child";
        this.selectedTreeNodeKey = selectedKeys[0]
        this.treeSelectedNode = node.dataRef.obj
      }
    },
    //树状控件参数选中查询
    onSelectQuery(selectedKey, node) {
      this.dataItemQuery({
        selectedKey: selectedKey,
        node,
      });
    },
    //参数Tree删除参数节点方法
    remove() {
      if (!this.selectedTreeNodeKey || !this.treeSelectedNode.dataSeqId) {
        this.$message.warn(this.$i18n.tc('menuItem.PermissionSettingsDelParameterWarn1'))
        return
      }
      if (this.selectedOption !== "child") {
        this.$message.warn(this.$i18n.tc('menuItem.PermissionSettingsDelParameterWarn2'))
        return
      }

      this.$confirm({
        title: this.$t('menuItem.PermissionSettingsDelParameter'),
        onOk: () => {
          return new Promise((resolve) => {

            this.removeTreeData({
              dataCate: this.treeSelectedNode.dataCate,
              dataSeqId: this.treeSelectedNode.dataSeqId,
              resolve
            });
            this.selectedTreeNodeKey = ''
            this.treeSelectedNode = {}
            this.selectedOption = ''
            this.cleanFormData();
          })

        }
      })
    },

    //新增参数
    add() {
      if (!this.selectedTreeNodeKey || !this.selectedOption) {
        this.$message.warn(this.$i18n.tc('menuItem.PermissionSettingsAddParameterWarn'))
        return
      }

      this.saveButtonShow = true;
      this.submitType = 'add';

      this.initAddParamForm()

      if(this.selectedOption === "cate"){
        this.handleItemChange(this.treeSelectedNode.dataId)
      }else if(this.selectedOption === "child"){
        this.handleItemChange(this.treeSelectedNode.dataCate)
      }
      // this.paramForm.dataCate = this.treeSelectedNode.dataId
      // console.log(this.paramForm)
      // console.log(this.treeSelectedNode)
    },
    //编辑参数项
    edit() {
      if (this.selectedOption != 'child') {
        this.$message.info(this.$i18n.tc('menuItem.PermissionSettingsUpdateParameterInfo'))
        return;
      }

      if (!this.saveButtonShow) {
        this.saveButtonShow = true;
        this.selectData.forEach(e => {
          if (e.key != 'dataCate') {
            e.disableFlag = false
          }
        })
        this.submitType = 'edit';
      } else {
        this.$message.warn(this.$i18n.tc('menuItem.PermissionSettingsAddParameterWarn'));
      }
    },
    //新增参数类型
    AddDataCate() {
      this.title = 'addParameterType'
      this.cateVisible = true;
      this.selectDataCateDesc = ''
      this.updateType = false
    },
    updateDataCate() {
      if (!this.selectedTreeNodeKey || !this.treeSelectedNode.dataId || this.selectedOption !== "cate") {
        this.$message.warn(this.$i18n.tc('menuItem.PermissionSettingsUpdateParameterTypeWarn1'))
        return
      }
      this.title = 'updateParameterType'
      this.cateVisible = true;
      this.updateType = true
      this.updateTypeFunc(this.treeSelectedNode.dataId)
      this.queryCateDataCnt(this.treeSelectedNode.dataId)
    },
    //删除参数类型
    deleteDataCate() {
      if (!this.selectedTreeNodeKey || !this.treeSelectedNode.dataId) {
        this.$message.warn(this.$i18n.tc('menuItem.PermissionSettingsDelParameterTypeWarn'))
        return
      }

      if (this.selectedOption !== "cate") {
        this.$message.warn(this.$i18n.tc('menuItem.PermissionSettingsDelParameterTypeWarn2'))
        return
      }
      this.deleteValue = this.treeSelectedNode.dataId

      this.deleteVisible = true;
    },
    closeModal() {
      this.cateVisible = false
      this.clearModal()
    },

    //清除弹出框的信息
    clearModal() {
      let form = {}
      Object.keys(this.cateForm).forEach(key => {
        if (this.cateForm[key] && lodash.isPlainObject(this.cateForm[key]) && 'value' in this.cateForm[key]) {
          form[key] = {
            value: '',
            mainFlg: false,
            valueType: VALUE_TYPE_STR, valueMax: null, valueMin: null,
            valueLength: null,
            valueAccuracy: null,
          }
        } else {
          form[key] = ''
        }
      })
      this.setCateForm(form)
      this.$refs.cateAddForm.resetFields()
    },
    //参数信息提交保存
    handleSubmit() {
      this.$refs.paramForm.validate(valid => {
        if (valid) {

          if (!this.paramForm.dataCate) {
            this.$message.warn(this.$i18n.tc('menuItem.PermissionSettingsDelParameterTypeWarn'))
            return
          }
          let title = '';
          let successPrompt = '';

          if (this.submitType === 'add') {
            title = '请确认是否新增参数！';
            successPrompt = this.$i18n.tc('menuItem.PermissionAddSuccess');
          } else {
            title = '请确认是否修改参数！';
            successPrompt = this.$i18n.tc('menuItem.PermissionUpdateSuccess');
          }
          let codeInTrx = {
            trxId: "bisData",
            actionFlg: "Q",
            iary: [{
              dataCate: this.paramForm.dataCate
            }]
          };
          // let addAble = true
          SendMsg.sendPostTrx(codeInTrx).then(({data}) => {
            if (data.rtnCode === "0000000") {

              // if(this.mainFlgArray.length !==0){
              //     let index = data.oary.findIndex( e => {
              //         let sameFlg = true
              //         this.mainFlgArray.forEach( flg => {
              //             if(e[flg] !== this.paramForm[flg]){
              //                 sameFlg = false
              //                 return
              //             }
              //         })
              //         return !sameFlg
              //     })
              //     if(index !== -1){
              //         addAble = false
              //     }
              // }
              //
              // if(!addAble){
              //     if (this.submitType === 'add') {
              //         this.$message.warn("参数已存在，新增失败")
              //     }else{
              //         this.$message.warn("参数已存在，修改失败")
              //     }
              //     return;
              // }

              this.$confirm({
                title: this.$t('menuItem.PermissionSettingsAddParameter'),
                okText: this.$t('menuItem.confirm'),
                cancelText: this.$t('menuItem.cancel'),
                onOk: () => {
                  this.saveLoading = true
                  if (this.submitType === 'add') {
                    this.addTreeData({
                      params: this.paramForm,
                      successPrompt: successPrompt,
                      callback: (flg) => {
                        this.saveLoading = false
                        if (flg) {
                          this.add()
                        }
                      },
                    });
                  } else {
                    this.updateTreeData({
                      params: this.paramForm,
                      successPrompt: successPrompt,
                      hideSaveButton: () => {
                        this.saveButtonShow = false
                      },
                      endLoading: () => {
                        this.saveLoading = false
                      }
                    });
                  }

                },
                onCancel: () => {
                  this.saveLoading = false
                }
              });
            }
          });
        }
      })
    },
    //参数input值改变方法
    handleChange(value, key) {
      this.selectData.map(data => {

        if (key === data.key) {
          if (data.key === 'dataDesc') {
            this.$set(data, 'value', value);
            this.dataDesc = data.value;
          } else if (data.key === 'dataExt') {
            this.$set(data, 'value', value);
            this.dataExt = data.value;
          } else if (data.key === 'dataCate') {
            this.$set(data, 'value', value);
            this.dataCate = data.value;
          } else if (data.key === 'dataId') {
            this.$set(data, 'value', value);
            this.dataId = data.value;
          } else if (data.key === 'dataItem') {
            this.$set(data, 'value', value);
            this.dataItem = data.value;
          } else if (data.key === 'dataSeqId') {
            this.$set(data, 'value', value);
            this.dataSeqId = data.value;
          } else if (data.key === 'unqSeqId') {
            this.$set(data, 'value', value);
            this.unqSeqId = data.value;
          } else if (data.key === 'ext1') {
            this.$set(data, 'value', value);
            this.ext1 = data.value;
          } else if (data.key === 'ext2') {
            this.$set(data, 'value', value);
            this.ext2 = data.value;
          } else if (data.key === 'ext3') {
            this.$set(data, 'value', value);
            this.ext3 = data.value;
          } else if (data.key === 'ext4') {
            this.$set(data, 'value', value);
            this.ext4 = data.value;
          } else if (data.key === 'ext5') {
            this.$set(data, 'value', value);
            this.ext5 = data.value;
          }else if (data.key === 'ext6') {
            this.$set(data, 'value', value);
            this.ext6 = data.value;
          } else if (data.key === 'ext7') {
            this.$set(data, 'value', value);
            this.ext7 = data.value;
          } else if (data.key === 'ext8') {
            this.$set(data, 'value', value);
            this.ext8 = data.value;
          } else if (data.key === 'ext9') {
            this.$set(data, 'value', value);
            this.ext9 = data.value;
          } else if (data.key === 'ext10') {
            this.$set(data, 'value', value);
            this.ext10 = data.value;
          }
        }
      });
    },
    //新增参数类型确认保存
    handleAddModal() {
      let data = [{
        dataCate: 'CATE',
        dataId: this.cateForm.m_para_type,
        dataDesc: this.cateForm.m_para_desc,
        authFlg: this.cateForm.authFlg
      }]
      Object.keys(this.cateForm).forEach(key => {
        if (this.cateForm[key] && this.cateForm[key].value) {
          data.push({
            dataCate: 'CODE',
            dataExt: this.VALUE_NAME[key],
            dataDesc: this.cateForm[key].value,
            ext1: this.cateForm[key].mainFlg,
            ext2: this.cateForm[key].valueType,
            ext3: this.cateForm[key].valueType === VALUE_TYPE_STR ? this.cateForm[key].valueLength : this.cateForm[key].valueMax,
            ext4: this.cateForm[key].valueMin,
            ext5: this.cateForm[key].valueAccuracy,
            dataSeqId: this.cateForm[key].dataSeqId,
            defaultValue: this.cateForm[key].defaultValue,
          })
        }
      })
      this.addCateData({
        data,
        callback: () => {
          this.clearModal()
          this.cateVisible = false
          this.saveButtonShow = false
          this.queryTreeData()
        },
        updateType: this.updateType
      });


    },

    //新增参数类型确认弹出确认框
    handleOk() {
      this.$refs.cateAddForm.validate(valid => {
        if (valid) {
          let hasMainFlg = false
          Object.keys(this.cateForm).forEach(key => {
            if (this.cateForm[key] && this.cateForm[key].value && this.cateForm[key].mainFlg) {
              hasMainFlg  = true
            }
          })
          if(!hasMainFlg){
            this.$message.warn(this.$i18n.tc('menuItem.PermissionSettingsAddParameterTypeWarn'))
            return
          }

          let flag = true
          Object.keys(this.VALUE_NAME).forEach(key => {
            let refForm = this.$refs[this.VALUE_NAME[key]]
            if (refForm) {
              refForm.$children[0].validate(valid => {
                if (!valid) {
                  flag = false
                }
              })
            }
          })
          if (flag) {
            this.$confirm({
              title: this.updateType ? this.$i18n.tc('menuItem.PermissionSettingsUpdateParameterType')
                  : this.$i18n.tc('menuItem.PermissionSettingsAddParameterType'),
              okText: this.$i18n.tc('menuItem.confirm'),
              cancelText: this.$i18n.tc('menuItem.cancel'),
              onOk: () => {
                this.handleAddModal();
                // this.queryTreeData()
              },
              onCancel: () => {

              }
            });
          }
        }
      });
    },
    //删除参数类型确认弹出确认框
    handleDeleteOk() {
      if (this.deleteValue) {
        this.$confirm({
          title: this.$i18n.tc('menuItem.PermissionSettingsDelParameterType')+`[${this.deleteValue}]`,
          okText: this.$i18n.tc('menuItem.confirm'),
          cancelText: this.$i18n.tc('menuItem.cancel'),
          onOk: () => {
            this.removeCateData({
              dataCate: this.deleteValue,
              callback: () => {
                this.deleteVisible = false;
                this.selectedTreeNodeKey = ''
                this.selectedOption = ''
                this.treeSelectedNode = {}
                this.deleteValue = ''
                this.queryTreeData()
              }
            });

          },
        });
      } else {
        this.$message.warn(this.$i18n.tc('menuItem.PermissionSettingsDelParameterTypeWarn'))
      }

    },

    //界面参数下拉菜单值改变方法
    handleItemChange(value) {
      let index = this.cateData.findIndex(e => e.dataId == value)
      let dataId = this.cateData[index].dataId
      this.requestCode({dataId: dataId, dataCate: value})
    },
  },
  mounted() {
    this.queryTreeData();
  },
  watch: {
    selectData: function (val) {
      this.paramForm = {}
      val.forEach((data) => {
        this.$set(this.paramForm, data.key, data.value)
      });
    },
    cateForm: {
      deep: true,
      handler(val) {
        let isVal = Object.keys(this.VALUE_NAME).some(key => val[key] && val[key].value)
        if (isVal) {
          this.modalWidth = '80%'
          this.settingCol = 8
        } else {
          this.modalWidth = '30%'
          this.settingCol = 24
        }
      }
    }
  }
}
</script>

<style scoped>

.ant-tabs-nav .ant-tabs-tab {
  padding-top: 2px;
  padding-bottom: 8px;
}

.ant-tabs-bar {
  margin-bottom: 0px;
}

.ant-tabs .ant-tabs-top-content.ant-tabs-content-animated, .ant-tabs .ant-tabs-bottom-content.ant-tabs-content-animated {
  height: 460px;
}

</style>
